<template>
	<view class="container">
		<view class="top">
			<text class="title">审批分类:<text>{{processInsName}}</text></text>
			<text class="applicant">申请人:<text>{{operatorText}}</text></text>
		</view>
		<!-- 物资领用流程 -->
		<view class="materialData">
			<view class="material"  v-for="(item,index) in storeCorrectionDetails" :key="index">
				<table cellSpacing="0" cellpadding="1" width="100%" class="ctl">
				    <tBody>
				        <tr>
							<td class="td_1">物资名称:</td>
							<td class="td">{{item.name}}</td>
						</tr>
						<tr>
							<td class="td_1">仓库名称:</td>
							<td class="td">{{item.sname}}</td>
						</tr>
						<tr>
							<td class="td_1">入库单号:</td>
							<td class="td">{{item.storeInoutNo}}</td>
						</tr>
						<tr>
							<td class="td_1">入库数量:</td>
							<td class="td">{{item.storeInoutNum}}</td>
						</tr>
						<tr>
							<td class="td_1">单价:</td>
							<td class="td">{{item.unitPrice}}</td>
						</tr>
						<tr>
							<td class="td_1">总金额:</td>
							<td class="td">{{item.storeInoutTotal}}</td>
						</tr>
						<tr>
							<td class="td_1">校正数量:</td>
							<td class="td">{{item.corrNum}}</td>
						</tr>
						<tr>
							<td class="td_1">校正金额:</td>
							<td class="td">{{item.corrTotal}}</td>
						</tr>
						<tr>
							<td class="td_1">入库时间:</td>
							<td class="td">{{item.storeInoutDate}}</td>
						</tr>
				    </tBody>
				</table>
			</view>
			<view class="reviewComments">
				<view><text>审核意见:</text></view>
				<hr>
				<scroll-view scroll-y="true" class="scrollview">
					<textarea class="textarea" maxlength="2000" v-model="opinion" placeholder="请输入审核意见"></textarea>
				</scroll-view>
			</view>
		</view>
		<view class="result">
			<view>
				<view :class="{fail:current==2}" @click="fail()">
					<text>不通过</text>
				</view>
				<view :class="{fail:current==1}" @click="adopt()">
					<text>通过</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				auditResult:'',
				businessId:'',
				opinion:'',
				processInstanceId:'',
				taskInstanceId:'',
				auditor:'',
				processInsName:'',
				flowNo:'',
				businessId:'',
				flowName:'',
				username:'',
				current:1,
				id:'',
				operatorText:'',
				command: {},
				storeCorrectionDetails:[],
			}
		},
		onLoad: function(option) { //option为object类型，会序列化上个页面传递的参数
			this.businessId = option.businessId
			this.processInsName= option.processInsName
			this.flowNo=option.flowNo
			this.flowName=option.flowName
			console.log(this.flowNo,this.businessId,this.processInsName, this.flowName)
			// console.log(this.flowNo, this.flowName)
			this.materialRequisition()
			this.getUser()
		},
		methods: {
			async materialRequisition(){
				const res = await this.$myRequest({
					url: '/api-store/checkApproval/' + this.businessId,
					method: "get",
				})
				if (res.success == true) {
				    this.id=res.body.command.id
					this.operatorText=res.body.taskInstance.processInstance.operatorText
					this.processInstanceId= res.body.taskInstance.processInstance.processInstanceId
					this.taskInstanceId= res.body.taskInstance.taskInstanceId
					this.warehouse()
				}
			},
			async warehouse(){
				const res = await this.$myRequest({
					url: '/api-store/storeChecks/storeCheckCorrInListByCid/' + this.id,
					method: "get",
				})
				if (res.success == true) {
					this.storeCorrectionDetails=res.body.storeCorrectionDetails
				}
			},
			async getUser() {
				const res = await this
					.$myRequest({
						url: '/api-portal/currentUser'
					})
				if (res.success == true) {
					this.auditor = res.body.currentUser.name;
					// console.log(JSON.stringify(res.body.currentUser))
				}
			},
			adopt() {
				console.log("通过")
				if (this.opinion == '') {
					this.opinion = "通过"
				}
				this.auditResult = "01"
				const res = this.$myRequest({
					url: '/api-flow/api/save',
					method: "post",
					data: {
						auditResult: this.auditResult,
						auditor: this.auditor,
						businessId: this.businessId,
						opinion: this.opinion,
						processInstanceId: this.processInstanceId,
						taskInstanceId: this.taskInstanceId,
					}
				})
				if (res.success == true) {
					console.log(JSON.stringify(res))
				}
				console.log(this.businessId)
				console.log(this.processInstanceId)
				console.log(this.taskInstanceId)
				console.log(this.auditResult)
				console.log(this.auditor)
				console.log(this.opinion)
				this.current = 1;
				uni.redirectTo({
				    url: '/pages/approve/index'
				});
			},
			fail() {
				console.log("不通过")
				if (this.opinion == '') {
					this.opinion = "不通过"
				}
				this.auditResult = "02"
				const res = this.$myRequest({
					url: '/api-flow/api/save',
					method: "post",
					data: {
						auditResult: this.auditResult,
						auditor: this.auditor,
						businessId: this.businessId,
						opinion: this.opinion,
						processInstanceId: this.processInstanceId,
						taskInstanceId: this.taskInstanceId,
					}
				})
				if (res.success == true) {
					console.log(JSON.stringify(res))
				}
				this.current = 2;
				uni.redirectTo({
				    url: '/pages/approve/index'
				});
			},
		}
	}
</script>

<style lang="scss">
	.top{
		width: 100%;
		height: 160rpx;
		background-color: #FFFFFF;
		color: #959595;
		.title{
			font-size: 28rpx;
			font-weight: bold;
			position: absolute;
			left: 65rpx;
			margin-top: 30rpx;
			text{
				margin-left: 10rpx;
				font-size: 28rpx;
				font-weight: bold;
				color: #000000;
			}
		}
		.applicant{
			font-size: 28rpx;
			font-weight: bold;
			position: absolute;
			left: 65rpx;
			margin-top:  80rpx;
			text{
				margin-left: 10rpx;
				font-size: 28rpx;
				font-weight: bold;
				color: #000000;
			}
		}
		.time{
			font-size: 28rpx;
			position: absolute;
			left: 65rpx;
			margin-top: 130rpx;
			color: #959595;
		}
	}
	.materialData{
		.material{
			width: 84%;
			height: auto;
			border-radius: 10rpx;
			margin: 20rpx auto 0 auto;
			padding-left: 40rpx;
			padding-right: 20rpx;
			font-size: 28rpx;
			font-weight: bold;
			color: #959595;
			background-color: #FFFFFF;
			.ctl{
				padding: 20rpx 0;
				table-layout:fixed;
				.td_1{
					vertical-align:top;
					width: 25%;
					word-break:break-all;
				}
								
				.td{
				        word-break:break-all;
						font-size: 28rpx;
						font-weight: bold;
						color: #000000;
				    }
			    }
		}
		.reviewComments{
			width: 84%;
			height: 170px;
			font-size: 28rpx;
			font-weight: bold;
			border-radius: 10rpx;
			margin: 20rpx auto 0 auto;
			padding-left: 40rpx;
			padding-right: 20rpx;
			background-color: #FFFFFF;
			color: #959595;
			.textarea{
				width: 100%;
				height: 110px;
				font-size: 28rpx;
				font-weight: bold;
				color: #000000;
			}
			view{
				padding-top: 30rpx;
				width: 100%;
				height: 50rpx;;
				line-height: 50rpx;;
			}
			hr{
				width: 100%;
				height: 2px;
				border: 0;
				margin-bottom: 10rpx;
				background-color: #c3c7cc;
			}
		}
	}
	.result{
		width: 92%;
		height: 80rpx;
		line-height: 80rpx;
		margin: 40rpx auto 50rpx  auto ;
		display: flex;
		justify-content: space-between;
		view{
			display: flex;
			width: 100%;
			view{
				margin: 0 ;
				padding: 0;
				width: 50%;
				border:1px solid;
				color: #109EF8;
				text{
					text-align: center;
					color: #109EF8;
					width: 100%;
				}
			}
			.fail{
				margin: 0 ;
				padding: 0;
				width: 50%;
				background-color: #109EF8;
				border:1px solid;
				color: #109EF8;
				text{
					text-align: center;
					color: #FFFFFF;
					width: 100%;
				}
			}
		}
	}
</style>
